<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<script type="text/javascript" src="${path}/plug-in/jquery-easyui-1.5.1/plugins/datagrid-cellediting.js"></script>
<title>清单配置</title>
<script>
	var rFn = null;
	$(function(){
		rFn = {
			saveEditor:function(index){
			},
			openEditor:function(index){
				//$("#dataGrid").datagrid('beginEdit',index);
			}
		};
		/*列表初始化*/
		var gridParam = {
				url:"/console/com.fs.jzzn.pojo.DetailedList/list",
				queryParams: {
					pNo: '${tid}',
					pNo_searchType: 'eq'
				},
			    columns : [ [
	             	{"field" : "cType","width" : 120,"title" : "物料类别"}, 
					{"field" : "cNO","width" : 120,"title" : "物料编码"}, 
					{"field" : "designNumber","width" : 120,"title" : "设计数量",editor:{type:'numberbox'}}, 
					{"field" : "actualNumber","width" : 120,"title" : "实际数量",editor:{type:'numberbox'}},
					{"field" : "remark","width" : 220,"title" : "备注说明",editor:{type:'text'}}
					/*,{field: "opt", title: "操作", width: 180, align: "center",formatter: function(value,row,index){
			     		return "<a href='javascript:void(0);' onclick='openEditor('"+ index +"')'>开启编辑</a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick='rFn.saveEditor('"+ index +"')'>保存编辑</a>";
			     	}}*/
            ]],
            onLoadSuccess:function(data){
				p.total({tip:'合计:', tipName:'cNO', 
					fields:[
				    	{name:'designNumber',total:'sum'},
				    	{name:'actualNumber',total:'sum'}
					] 
				});
			},
			onBeginEdit:function(index, row){
				if(row && row.id){
					return true;
				}else{
					$("#dataGrid").datagrid('cancelEdit',index);
				}
			},
			onAfterEdit:function(index, row, changes){
				if(row.id==undefined){
					$("#dataGrid").datagrid('endEdit',index);
					return false;
				}
				var data = $.extend(row, changes);
				$.getJSON("/console/com.fs.jzzn.pojo.DetailedList/modify", data, function(result){
					/*清除选中缓存数据*/
					p.dataGrid.datagrid('clearSelections');
					if(result.flag){
						p.gridQuery();
						p.tip({msg: '编辑成功！'});  
					}else{
						p.tip({msg: '编辑保存出现异常！'}); 
					}
				});
			},
			singleSelect : true
		};
		//p.dataGrid = $(p.dataGrid).datagrid( $.extend({}, p.dataGridParam, gridParam)).datagrid('enableCellEditing');
		p.dataGrid = $(p.dataGrid).datagrid( $.extend({}, p.dataGridParam, gridParam)).datagrid('enableCellEditing');
		/*事件响应*/
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var id = $(this).attr("motion_code");
			switch (id) {
			case "01":
				p.gridAdd({ title : "清单配置新增", width : 600, height : 250,href:"/console/theLibrary/rewrite/add?id="+'${tid}' });
				break;
			case "02":
				p.gridDelete({url:"/console/com.fs.jzzn.pojo.DetailedList/delete"});
				break;
			case "05":
				p.gridQuery({});
				break;
			case "07":
				p.down({filename:'单项工程清单配置统计_${tid}',url:'/console/detailedList/export',local:true });
				break;
			default:
				break;
			}
		});
	});
</script>
</head>
<body  class="easyui-layout">
		<!-- 但行高度33px，多行时 33乘以行数  -->
		<div id="querybar" data-options="region:'north',split:false,border:false" style="height:33px;">
			<div class="easyui-panel" data-options="fit:true,border:false">
				<!-- 查询条件表单，根据配置进行替换  -->
				<form id="queryForm" >
				 <input type="hidden" name="className" value="com.fs.jzzn.pojo.DetailedList" />
				 <input type="hidden" name="pNo" value="${tid}" />
				 <input type="hidden" name="pNo_searchType" value="eq" />
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="" style="width:400px;" value="${tName }" data-options="label:'工程路段:',required:false" readonly/>
				 </div>
				</form>
			</div>
		</div>  
	
		<!-- 工具栏按钮 -->
		<div id="toolbar" class="easyui-panel" style="padding:3px;">
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-add" plain="true" motion_code="01">新增</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cut" plain="true" motion_code="02">删除</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" plain="true" motion_code="05">刷新</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-excel" plain="true" motion_code="07">导出</a>
		</div>
		
		<!-- 表格 -->
		<div region="center" border="false">
			<table id="dataGrid"></table>
		</div>
</body>
</html>